﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using UPC.UbicaTuReu.WEB.Models;
using UPC.UbicaTuReu.WEB.Dominio;

namespace UPC.UbicaTuReu.WEB.Controllers
{
    public class AgendaController : Controller
    {
        
        WSUsuario.UsuariosClient proxyUsuario = new WSUsuario.UsuariosClient();
        WSAgenda.AgendaServiceClient proxyAgenda = new WSAgenda.AgendaServiceClient();


        // GET: /Agenda/
        public ActionResult Index()
        {
            return View(proxyAgenda.ListarAgenda());
        }

        //
        // GET: /Agenda/Details/5

        public ActionResult Details(int id)
        {
            return View();
        }

        //
        // GET: /Agenda/Create

        public ActionResult Create()
        {
            SalaModels oSalaModel = new SalaModels();
            ICollection<Salas> lstSalas = oSalaModel.CargarSalas();
            ViewData["ListaSalas"] = new SelectList(lstSalas, "SalaID", "SalaNombre");

            ICollection<Horario> lstHoraInicio = oSalaModel.CargarHoras();
            ViewData["ListaHoraInicio"] = new SelectList(lstHoraInicio, "Hora", "Hora");

            ICollection<Horario> lstHoraFin = oSalaModel.CargarHoras();
            ViewData["lstHoraFin"] = new SelectList(lstHoraFin, "Hora", "Hora");

            return View();            
        } 

        //
        // POST: /Agenda/Create

        [HttpPost]
        public ActionResult Create(FormCollection collection)
        {
            try {

                string asunto = (string)collection["Asunto"];
                string descripcion = (string)collection["Descripcion"];
                string fecha = (string)collection["Fecha"];
                string horaInicio = (string)collection["ddlHoraInicio"];
                string horaFin = (string)collection["ddlHoraFin"];
                int salaID = int.Parse(collection["ddlSalas"].ToString());

                proxyAgenda.CrearAgenda(asunto, fecha, horaInicio, horaFin, descripcion, salaID);
                return RedirectToAction("../AgendaUsuario/Create");

            }
            catch {
                return View();
            }

            
        }
        
        //
        // GET: /Agenda/Edit/5
 
        public ActionResult Edit(int id)
        {
            return View();
        }

        //
        // POST: /Agenda/Edit/5

        [HttpPost]
        public ActionResult Edit(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add update logic here
 
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

        //
        // GET: /Agenda/Delete/5
 
        public ActionResult Delete(int id)
        {
            return View();
        }

        //
        // POST: /Agenda/Delete/5

        [HttpPost]
        public ActionResult Delete(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add delete logic here
 
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
    }
}
